<%@page contentType="text/html;charset=utf-8" pageEncoding="UTF-8"%>
<%@taglib prefix="t" tagdir="/WEB-INF/tags"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<t:template>
	<jsp:attribute name="include">
		<script type="text/javascript">
			function reloadTable() {
				var table = $('#merchTable').dataTable();
				table.fnReloadAjax();
			}

			function delPicture(id) {
				$.post('<c:url value="/shop/delPicture"/>', {
					merchId : id
				}, reloadTable);
			}

			var serverDatas = [ "categoryId" ];

			function pageInit() {
				createDataTable("merchTable", '<c:url value="/administration/sales/getSales"/>', [
						linkFormattedColDef(0, '<c:url value="/profile"/>', "username"), {
							"sName" : "name",
							"aTargets" : [ 1 ],
							"bSortable" : true,
							"mData" : function(data, type, full) {
								return '<a href="<c:url value="/shop/sales"/>/' + data.id + '">' + data.name + '</a>';
							}
						}, colDefNotSortable(2, "category.label"), colDef(3, "price"), dateColDef(4, "lastchange"), {
							"sName" : "setting",
							"aTargets" : [ 5 ],
							"bSortable" : false,
							"mData" : function(data, type, full) {
								return '<a href="#" onclick="delPicture(' + data.id + ');return false;"/>Kép törlése</a>';
							}
						} ], true);
				var selectGen = $('#selectGen');
				$("#merchTable_filter>label>input").replaceWith(selectGen.html());
				selectGen.remove();
			}
		</script>
	</jsp:attribute>

	<jsp:attribute name="pagetitle">
		Hirdetések kezelése
    </jsp:attribute>
	<jsp:body>
		<div id="selectGen">
			<select id="categoryId" name="categoryId" data-size="7"
				onchange="reloadTable()">
				<option value="0">Mind</option>
				${categoryOptions }
			</select>
		</div>
    	<table id="merchTable">
		    <thead>
				<tr>
					<th>Felhasználó</th>
					<th>Megnevezés</th>
					<th>Kategória</th>
					<th>Ár (Ft)</th>
					<th>Utolsó módosítás</th>
					<th>&nbsp;</th>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
				</tr>
			</tbody>
			<tfoot>
				<tr>
					<th>Felhasználó</th>
					<th>Megnevezés</th>
					<th>Kategória</th>
					<th>Ár (Ft)</th>
					<th>Utolsó módosítás</th>
					<th>&nbsp;</th>
				</tr>
			</tfoot>
    	</table>
    </jsp:body>
</t:template>